# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.wait import WebDriverWait
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.support.expected_conditions import *


import unittest, time

class Untitled2(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "http://localhost/"
        self.verificationErrors = []
        self.accept_next_alert = True

    def test_untitled2(self):
        driver = self.driver
        driver.get(self.base_url + "/php4dvd/")
        driver.find_element_by_id("username").clear()
        driver.find_element_by_id("username").send_keys("admin")
        driver.find_element_by_name("password").clear()
        driver.find_element_by_name("password").send_keys("admin")
        driver.find_element_by_name("submit").click()

        search = driver.find_element_by_id("q")
        search.clear()
        search.send_keys("edge")
        search.send_keys(Keys.ENTER)
        time.sleep(2)

        wait = WebDriverWait(driver, 10)
        if wait.until(presence_of_element_located((By.XPATH, ".//*[@id='results']/a[1]"))):
            search = driver.find_element_by_id("q")
            search.clear()
            search.send_keys("56")
            search.send_keys(Keys.ENTER)
            time.sleep(2)

            wait = WebDriverWait(driver, 10)
            if wait.until(presence_of_element_located((By.XPATH, ".//*[@id='results']/div[1]"))):
                return True
            else:
                return False
        else:
            return False


    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()
